/**
 * 
 */
package com.appRating;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.widget.Button;

import com.bitBusy.manageyourriches.utilityClasses.display.DisplayButtonValueUsers;
import com.bitBusy.manageyourriches.utilityClasses.display.DisplayMessages;

/**
 * @author SumaHarsha
 *
 */
public class RateAppWorker implements DisplayButtonValueUsers{
	
    private final static String APP_PNAME = "com.bitBusy.manageyourriches";

	 private static final String RATENOW = "Sure, why not?";
	    private static final String REMINDLATER = "Will do later";
	    private static final String NO = "NO";
	    
	    private Context myContext;

		private Editor myEditor;

	    public RateAppWorker(Context the_context, Editor the_editor)
	    {
	    	myContext = the_context;
	    	myEditor = the_editor;
	    }
	/* (non-Javadoc)
	 * @see com.bitBusy.manageyourriches.utilityClasses.display.DisplayButtonValueUsers#getButtonClickOnDialog(android.widget.Button)
	 */
	@Override
	public void getButtonClickOnDialog(Button the_button) {

		if(the_button != null) 
			{
			String buttonText = the_button.getText().toString();
			if (buttonText != null)
			{
				if(RATENOW.equals(buttonText))
				{
	                myContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME)));

				}
				else if(NO.equals(buttonText))
				{
					if (myEditor != null) {
	                    myEditor.putBoolean("dontshowagain", true);
	                    myEditor.commit();
	                }
	            }
			}
		}
	}
	

	/**
	 * @param mContext
	 * @param editor
	 */
	public void showDialog() {
		if (myContext != null)
		{
			DisplayMessages.displayDialogWithThreeButtonsOnly
			(myContext, this, "Please rate the app?", RATENOW, REMINDLATER, NO);
		}
	}

}
